package org.syncsoft.overalt.domain.document.joson;

import java.util.ArrayList;
import java.util.Collection;

import org.syncsoft.overalt.common.json.JSonTree;
import org.syncsoft.overalt.domain.document.entity.Document;

/**
 * 
 * @author tptfc
 *
 */
public class DocumentsJsonConverter extends AbstractDocumentJsonConverter<Collection<Document>> {
	/*
	 * (non-Javadoc)
	 * @see org.syncsoft.overalt.common.json.AbstractJsonConverter#converter(org.syncsoft.overalt.common.json.JSonTree)
	 */
	@Override
	protected Collection<Document> converter(JSonTree jsonTree) {
		Collection<Document> documents = null;
		
		if (jsonTree != null) {
			documents = new ArrayList<Document>();
		
			Collection<JSonTree> entities = jsonTree.getJsonTreesFronEntityName("entities");
			
			for (JSonTree entity : entities) {
				Document document = extractDocument(entity, entity);
				
				if (document != null) {
					documents.add(document);
				}
			}
		}
		
		return documents;
	}
	
}
